#******************************************************************************
#* Makefile for JDS's application and libary
#* 
#* This file is main Makefile of a project.
#*
#* 2009.02.13 dlx, create
#******************************************************************************


#******************************************************************************
#* Set the dir and name of your project. 
#******************************************************************************
PROJECT_DIR = E:/JDS/PROJS/testApp
PROJECT_NAME = testApp

#******************************************************************************
#* Set the name of vm you slected
#******************************************************************************
#VM_NAME = lpc2210
VM_NAME = easyRAM213X

#******************************************************************************
#* add the user libary you want. here ...
#******************************************************************************
USER_LIBS = mainLib.a uartLib.a testLib.a

#******************************************************************************
#* add the JDS libary you want. here ...
#******************************************************************************
JDS_LIBS = cmLib.a

#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

#******************************************************************************
#* Should not be change. here ...
#******************************************************************************
ifeq (${VM_NAME},lpc2210)
	VM_DIR = ${JDS_ROOT}/SRC/vm/${VM_NAME}
	VM_CFG_DIR = ${VM_DIR}/vmCfg
endif

ifeq (${VM_NAME},easyRAM213X)
	VM_DIR = ${JDS_ROOT}/SRC/vm/${VM_NAME}
	VM_CFG_DIR = ${VM_DIR}/vmCfg
endif

ifeq (${VM_DIR},)
$(error "Unknow vm name: ${VM_NAME}")
endif

JDS_INCLUDE_DIR += -I${VM_DIR}/include
JDS_INCLUDE_DIR += ${addprefix -I${JDS_SRC_DIR}/, ${JDS_LIBS:Lib.a=/include}}
JDS_INCLUDE_DIR += ${addprefix -I${PROJECT_DIR}/, ${USER_LIBS:Lib.a=/include}}

JDS_SRC_DIR = ${JDS_ROOT}/SRC
JDS_MAKE_DIR = ${JDS_ROOT}/MAKE

export JDS_ROOT
export JDS_SRC_DIR
export JDS_MAKE_DIR
export VM_DIR
export VM_CFG_DIR
export JDS_INCLUDE_DIR
export PROJECT_DIR
export AT = @

TARGET = ${PROJECT_NAME}

-include ${VM_CFG_DIR}/vmCfg.mak

${TARGET}: lib vm 
	@${ECHO} ***************************************************************
	@${ECHO} Build ${PROJECT_NAME}
	${BUILD_TARGET}

vm: 
	@${MAKE} -C ${VM_DIR}
	@${ECHO} JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
	@${ECHO} Build VM:${VM_NAME} OK
	@${ECHO} JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
	@${ECHO} #

lib: ${USER_LIBS} ${JDS_LIBS} 
	@${ECHO} JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
	@${ECHO} Build library OK
	@${ECHO} JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
	@${ECHO} #

${JDS_LIBS}: %.a:
	@${ECHO} Build JDS library: $@
	${MAKE_JDS_LIB}

${USER_LIBS}: %.a:
	@${ECHO} Build USER library: $@
	${MAKE_USER_LIB}

cleanapp:
	@${RM} ${TARGET}.*

clean:	cleanapp
	@${RM} obj/*.o
	@${RM} lib/*.a


.PHONY: clean cleanapp vm

